<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='UTF-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>Document</title>
  <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>
</head>

<body>
  <template id="faCpn">
    <div>
      <p>我是父组件</p>
    <p>faMessage: {{faMessage}}</p>
    <ch-cpn @chmessage="recvMessage"></ch-cpn>
    </div>
  </template>
  <template id="chCpn">
   <div> <p>我是子组件</p>
    <p>chMessage: {{chMessage}}</p>
    <button @click="sendMessage">发送信息到父组件</button>
  </div>
  </template>
  <div id='app'>
    <fa-cpn></fa-cpn>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello world'
      },
      components: {
        faCpn: {
          template: '#faCpn',
          data() {
            return {
              faMessage: '我是父组件'
            }
          },
          methods: {
            recvMessage(value) {
              console.log(value);
            }
          },
          components: {
            chCpn: {
              template: '#chCpn',
              data() {
                return {
                  chMessage: '我是子组件'
                }
              },
              methods: {
                sendMessage() {
                  this.$emit('chmessage', this.chMessage)
                }
              }
            }
          }
        }
      }
    })
  </script>
</body>

</html>